home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Synchronization.h
-
- Contains: Synchronization Interfaces
-
- Version: Technology: System 8
- Release: Universal Interfaces 3.0d3 on Copland DR1
-
- Copyright: © 1984-1996 by Apple Computer, Inc. All rights reserved.
-
- Bugs?: If you find a problem with this file, send the file and version
- information (from above) and the problem description to:
-
- Internet: apple.bugs@applelink.apple.com
- AppleLink: APPLE.BUGS
-
- */
- #ifndef __SYNCHRONIZATION__
- #define __SYNCHRONIZATION__
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
- #ifndef __KERNEL__
- #include <Kernel.h>
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- #if PRAGMA_IMPORT_SUPPORTED
- #pragma import on
- #endif
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=power
- /* the following contents can only be used by compilers that support PowerPC struct alignment */
-
- #if FOR_SYSTEM8_PREEMPTIVE
- /* Note: Lock, ReadWriteLock, and CountingSemaphore data structures must be LONG WORD ALIGNED in memory!*/
- struct Lock {
- UInt32 theInfo[2];
- };
- typedef struct Lock Lock;
-
- typedef Lock *LockPtr;
- struct ReadWriteLock {
- UInt32 theInfo[5];
- };
- typedef struct ReadWriteLock ReadWriteLock;
-
- typedef ReadWriteLock *ReadWriteLockPtr;
- struct CountingSemaphore {
- UInt32 theInfo[6];
- };
- typedef struct CountingSemaphore CountingSemaphore;
-
- typedef CountingSemaphore *CountingSemaphorePtr;
- typedef OptionBits LockOptions;
-
- enum {
- kLockDisablesSwis = 0x00000001, /* disable software interrupts while locked*/
- kLockAdjustsPriorities = 0x00000002, /* lock prevents priority inversion*/
- kLockDisablesCompletionRoutines = 0x00000004 /* disable software interrupts and system 7 completion routines while locked*/
- };
-
- typedef void *InterruptState;
- /*
- Simple lock routines
- Locks may be created with the kLockDisablesSwis and/or kLockDisablesCompletionRoutines options,
- but no others.
- */
- extern OSStatus CreateLock(Lock *theLock, LockOptions theOptions);
-
- extern OSStatus DeleteLock(Lock *theLock);
-
- extern OSStatus BeginLockedSection(Lock *theLock);
-
- extern OSStatus TryBeginLockedSection(Lock *theLock);
-
- extern OSStatus EndLockedSection(Lock *theLock);
-
- extern Boolean IsLockedSectionHeld(Lock *theLock);
-
- /*
- Reader/writer lock routines
- ReadWriteLocks may be created with the kLockDisablesSwis, kLockDisablesCompletionRoutines,
- and/or kLockAdjustsPriorities options.
- */
- extern OSStatus CreateReadWriteLock(ReadWriteLock *theReadWriteLock, LockOptions theOptions);
-
- extern OSStatus DeleteReadWriteLock(ReadWriteLock *theReadWriteLock);
-
- extern OSStatus BeginReadLockedSection(ReadWriteLock *theReadWriteLock);
-
- extern OSStatus TryBeginReadLockedSection(ReadWriteLock *theReadWriteLock);
-
- extern OSStatus EndReadLockedSection(ReadWriteLock *theReadWriteLock);
-
- extern OSStatus BeginWriteLockedSection(ReadWriteLock *theReadWriteLock);
-
- extern OSStatus TryBeginWriteLockedSection(ReadWriteLock *theReadWriteLock);
-
- extern OSStatus EndWriteLockedSection(ReadWriteLock *theReadWriteLock);
-
- extern OSStatus ChangeWriteLockToReadLock(ReadWriteLock *theReadWriteLock);
-
- extern Boolean IsReadLockedSectionHeld(ReadWriteLock *theReadWriteLock);
-
- extern Boolean IsWriteLockedSectionHeld(ReadWriteLock *theReadWriteLock);
-
- extern ItemCount GetReadWriteLockReaderCount(ReadWriteLock *theReadWriteLock);
-
- extern TaskID GetReadWriteLockWriterID(ReadWriteLock *theReadWriteLock);
-
- /*
- Counting semaphore routines
- CountingSemaphores currently have no options.
- */
- extern OSStatus CreateCountingSemaphore(CountingSemaphore *theCountingSemaphore, LockOptions theOptions, SInt32 initialCount, SInt32 maximumCount);
-
- extern OSStatus DeleteCountingSemaphore(CountingSemaphore *theCountingSemaphore);
-
- extern OSStatus WaitForCountingSemaphore(CountingSemaphore *theCountingSemaphore);
-
- extern OSStatus SignalCountingSemaphore(CountingSemaphore *theCountingSemaphore);
-
- extern SInt32 GetCountingSemaphoreCount(CountingSemaphore *theCountingSemaphore);
-
- extern SInt32 GetCountingSemaphoreMaxCount(CountingSemaphore *theCountingSemaphore);
-
- extern ItemCount GetCountingSemaphoreWaiterCount(CountingSemaphore *theCountingSemaphore);
-
- /*
- Interrupt enabling and disabling. ** MAY ONLY BE CALLED FROM PRIVILEGED CODE!!! **
- Use very sparingly.
- */
- extern InterruptState DisableInterrupts(void );
-
- extern void RestoreInterrupts(InterruptState theState);
-
- /*
- Atomic operations on 8-, 16-, and 32-bit entities.
- ** OPERATIONS THAT CROSS WORD (32-BIT) BOUNDARIES WILL FAIL!!! **
- */
- extern Boolean CompareAndSwapAligned(UInt32 oldValue, UInt32 newValue, UInt32 *theValue);
-
- /* Note: TestAndSet uses PPC bit ordering, zero is the high bit, and theBit ranges from 0 - FFFFFFFF.*/
- extern Boolean TestAndSet(UInt32 theBit, UInt8 *startAddress);
-
- extern SInt8 IncrementAtomic8(SInt8 *value);
-
- extern SInt8 DecrementAtomic8(SInt8 *value);
-
- extern SInt8 AddAtomic8(SInt32 amount, SInt8 *value);
-
- extern UInt8 BitAndAtomic8(UInt32 mask, UInt8 *value);
-
- extern UInt8 BitOrAtomic8(UInt32 mask, UInt8 *value);
-
- extern UInt8 BitXorAtomic8(UInt32 mask, UInt8 *value);
-
- extern SInt16 IncrementAtomic16Aligned(SInt16 *theValue);
-
- extern SInt16 DecrementAtomic16Aligned(SInt16 *theValue);
-
- extern SInt16 AddAtomic16Aligned(SInt32 theAmount, SInt16 *theValue);
-
- extern UInt16 BitAndAtomic16Aligned(UInt32 theMask, UInt16 *theValue);
-
- extern UInt16 BitOrAtomic16Aligned(UInt32 theMask, UInt16 *theValue);
-
- extern UInt16 BitXorAtomic16Aligned(UInt32 theMask, UInt16 *theValue);
-
- extern SInt32 IncrementAtomicAligned(SInt32 *theValue);
-
- extern SInt32 DecrementAtomicAligned(SInt32 *theValue);
-
- extern SInt32 AddAtomicAligned(SInt32 theAmount, SInt32 *theValue);
-
- extern UInt32 BitAndAtomicAligned(UInt32 theMask, UInt32 *theValue);
-
- extern UInt32 BitOrAtomicAligned(UInt32 theMask, UInt32 *theValue);
-
- extern UInt32 BitXorAtomicAligned(UInt32 theMask, UInt32 *theValue);
-
- /* Atomic primitives for singly linked list manipulation.*/
- extern void PushListElementAtomic(void *theListHead, void *theListElement, UInt32 theLinkOffset);
-
- extern void *PopListElementAtomic(void *theListHead, UInt32 theLinkOffset);
-
- #endif
-
- #pragma options align=reset
- #endif /* PRAGMA_ALIGN_SUPPORTED */
-
- #if PRAGMA_IMPORT_SUPPORTED
- #pragma import off
- #endif
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif /* __SYNCHRONIZATION__ */
-
-